/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlet.medic;

import Logger.MyLogger;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author giovanni
 */
public class Richiamati extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        MyLogger.getLogger().debug("Servlet per vedere i pazienti già richiamati");
        
        try {
            out.print("<div id=\"dialog-modal\" title=\"Info Paziente\"><!-- Div usato per visualizzare le info pazienti --></div>"
                    + "<h2>Procedura per visualizzare i pazienti già richiamati</h2>"
                    + "In questa pagina è possibile visualizzare le vaccianzioni che sono state eseguite tra la data di inizio"
                    + "e quella di fine (Si noti che la data di fine è quella più recente).<br/>"
                    + "<form>"
                    + "<label for=\"from\">Data inizio arco temporale:</label> <input type=\"text\" name=\"datepicker\" id=\"from\" size=\"9\"/><br/>"
                    + "<label for=\"to\">Data fine arco temporale:</label> <input type=\"text\" name=\"datepicker\" id=\"to\" size=\"9\"/>"
                    + "</form>"
                    + "<table class=\"border maxwidth\">"
                    + "<thead>"
                    + "<tr>"
                    + "<th>Nome Paziente</th>"
                    + "<th>Medico</th>"
                    + "<th>Data Vaccinazione</th>"
                    + "<th># vaccinazione</th>"
                    + "</tr>"
                    + "</thead>"
                    + "<tbody><!-- Caricato tramite ajax ogni volta che si cambia il giorno --></tbody>"
                    + "</table>"
                    + "<input type=\"button\" onclick=\"mostra()\" value=\"Visualizza le vaccinazioni compiute\"/>"
                    + "<script>"
                    + "function mostra(){"
                    + "var from = $(\"#from\").val();"
                    + "var to = $(\"#to\").val();"
                    + "$.ajax({"
                    + "url: \"TabellaRichiami\","
                    + "dataType: \"html\","
                    + "data: {From: from, To: to},"
                    + "success: function (data){ $(\"tbody\").html(data); }"
                    + "})"
                    + "}"
                    + "$(function() {"
                    + "var dates = $( \"#from, #to\" ).datepicker({"
                    + "maxDate: \"0D\","
                    + "changeMonth: true,"
                    + "changeYear: true,"
                    + "onSelect: function( selectedDate ) {"
                    + "var option = this.id == \"from\" ? \"minDate\" : \"maxDate\","
                    + "instance = $( this ).data( \"datepicker\" ),"
                    + "date = $.datepicker.parseDate("
                    + "instance.settings.dateFormat ||"
                    + "$.datepicker._defaults.dateFormat,"
                    + "selectedDate, instance.settings );"
                    + "dates.not( this ).datepicker( \"option\", option, date );"
                    + "}"
                    + "});"
                    + "});"
                    + "function mostra_info(id){"
                    + "$( \"#dialog-modal\" ).dialog({"
                    + "height: 300,"
                    + "width: 300,"
                    + "modal: true"
                    + "});"
                    + "$.ajax({"
                    + "url: \"Mostra_paziente.jsp\","
                    + "dataType: \"html\","
                    + "data: {Id: id},"
                    + "success: function(data){"
                    + "$( \"#dialog-modal\" ).html(data);"
                    + "}"
                    + "});"
                    + "}"
                    + "</script>");

        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
